package cn.gdsdxy.controller;

import cn.gdsdxy.service.GoodsService;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@ResponseBody
public class GoodsController {
    @Autowired
    GoodsService goodsService;
    @GetMapping("/goods")
    public String getAllGoods(){
        String goods= JSON.toJSONString(goodsService.getAllGoods());
        return goods;
    }
    @GetMapping("/goods/iphone")
    public String getphoneGoods(){
        String goods= JSON.toJSONString(goodsService.getphoneGoods());


        return goods;
    }
    @GetMapping("/goods/airpos")
    public String getairposGoods(){
        String goods= JSON.toJSONString(goodsService.getairposGoods());
        return goods;
    }
    @GetMapping("/goods/ipad")
    public String getpadGoods(){
        String goods= JSON.toJSONString(goodsService.getpadGoods());
        return goods;
    }

    @GetMapping("/goods/mac")
    public String getmacGoods(){
        String goods= JSON.toJSONString(goodsService.getmacGoods());
        return goods;
    }

    @GetMapping("/goodsid/{id}")
    public String getidGoods(@PathVariable("id") int id){
        String goods= JSON.toJSONString(goodsService.getidGoods(id));
        return goods;
//        return  bookService.getAllBook().toString();
    }
    @GetMapping("/goodssearch/{title}")
    public String gettitleGoods(@PathVariable("title") String title){
        String goods= JSON.toJSONString(goodsService.gettitleGoods(title));
        return goods;
//        return  bookService.getAllBook().toString();
    }
}
